﻿using Games.Common;
using System;
using Xamarin.Forms;

namespace Games.Horse64
{
    class GameCell : ImageLabel
    {
        public static readonly ImageSource ImgHorse = ImageSource.FromFile("horse_horse.png");
        public static readonly string ImgPath = "horse_horse.png";
        CellStatus status;

        public event EventHandler Tapped;

        public GameCell()
        {
            BackgroundColor = Color.Transparent;
            TextColor = Color.Blue;
            TapGestureRecognizer tapGesture = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
            tapGesture.Tapped += (sender, args) =>
            {
                Tapped?.Invoke(this, EventArgs.Empty);
            };
            GestureRecognizers.Add(tapGesture);
        }

        public int Col { set; get; }

        public int Row { set; get; }

        public CellStatus Status
        {
            set
            {
                if(status != value)
                {
                    status = value;
                    if(status == CellStatus.Init)
                    {
                        BackImage = null;
                        Opacity = 1;
                        Text = null;
                    }
                    else if(status == CellStatus.Visited)
                    {
                        Opacity = 0.5;
                    }
                    else if(status == CellStatus.Current)
                    {
                        BackImage = ImgPath;
                    }
                }
            }
            get
            {
                return status;
            }
        }
    }
}